﻿using System;
using System.Collections.Generic;
using System.Text;
using Torch.WL.Business.Interface;
using Torch.FrameWork.Utility;
using Torch.WL.Entity.CleanChina;
using Torch.WL.Business.CleanChina;

namespace Torch.WL.Business
{
    public class PersonProvider : BaseProvider<PersonProvider.RequestDataInfo>, IDataProvider
    {
        public PersonProvider(string _jsonInfo): base(_jsonInfo)
        {

        }

        public IMessageInfo Do()
        {            
            message.data = ProcessResponseData();
            return message;            
        }

        private ResponseDataInfo ProcessResponseData()
        {
            if (postdata == null || postdata.data == null)
            {
                message.code = (int)MessageCodeType.WrongRequestPara;
                message.message = Utils.GetEnumDescription(MessageCodeType.WrongRequestPara);
                return null;
            }
            //use postdata.data to process responseData
            //ResponseDataInfo responseData = new ResponseDataInfo();
            TbPersonEntity entity = new TbPersonEntity ();
            entity.personName = postdata.data.name;
            entity.workCompany = postdata.data.company;
            entity.province = postdata.data.province;
            entity.city = postdata.data.city;
            entity.address = postdata.data.address;
            entity.email = postdata.data.email;
            entity.mobile = postdata.data.mobile;

            int personId = TbPersonManager.Instance().Add(entity);

            return null;         
        }

        public class RequestDataInfo 
        {
            public string name { get; set; }
            public string company { get; set; }
            public string address { get; set; }
            public string province{get;set;}
            public string city { get; set; }
            public string mobile { get; set; }
            public string email { get; set; }
        }

        public class ResponseDataInfo
        {
        }


    }
}
